import socket
import errno

from ..BaseIO import BaseIO

class NetlinxDMX(BaseIO):
    def __init__(self, **kwargs):
        super(NetlinxDMX, self).__init__(**kwargs)
        self.hostaddr = kwargs.get('hostaddr')
        self.hostport = kwargs.get('hostport')
    def do_connect(self):
        self.do_disconnect()
        self.socket = socket.socket()
        result = self.socket.connect_ex((self.hostaddr, self.hostport))
        print result
        if result == 0: self.connected = True
    def do_disconnect(self):
        if self.connected:
            self.socket.close()
        self.connected = False
    def _send(self, string):
        if self.connected:
            self.socket.send(string)
    def sendDMXValue(self, chan, value):
        self._send('C%s=%s!' % (chan, value))
        print 'C%s=%s!' % (chan, value)
    
